import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_boost/boost_navigator.dart';
import 'package:hzcloud_flt/common/videoplayer.dart';
import 'package:hzcloud_flt/feature/login.page.dart';
import 'package:hzcloud_flt/feature/service_workbench.page.dart';
import 'package:hzcloud_flt/feature/switchpark.page.dart';
import 'package:hzcloud_flt/feature/tabbar.dart';

import 'mine.page.dart';
class NativeModule extends RouterModule {
  RouterPage qrscan = RouterPage('/common/qr');
}
class CommonModule extends RouterModule {
  RouterPage videoPage = RouterPage('/common/video', routeFactory:(settings, uniqueId) {
    return PageRouteBuilder<dynamic>(
      settings: settings,
      pageBuilder: (_, __, ___) => VideoPlyer(),
    );
  });
  @override
  Map<String, FlutterBoostRouteFactory> routeFactory() {
    // TODO: implement routeFactory
    return {
      videoPage.path:videoPage.routeFactory
    };
  }
}
class PageModule extends RouterModule {
  RouterPage tabbarPage = RouterPage('/tab', routeFactory:(settings, uniqueId) {
    return PageRouteBuilder<dynamic>(
      settings: settings,
      pageBuilder: (_, __, ___) => TabbarPage(),
    );
  });
  RouterPage switchParkPage = RouterPage('/switchPark', routeFactory:(settings, uniqueId) {
    return CupertinoPageRoute(builder: (context){
      return SwitchParkPage();
    },settings: settings);
  });
  RouterPage serviceWorkbenchPage =
      RouterPage('/service/workbench', routeFactory:(settings, uniqueId) {
    return PageRouteBuilder<dynamic>(
      settings: settings,
      pageBuilder: (_, __, ___) => ServiceWorkBench(),
    );
  });
  RouterPage loginPage =
  RouterPage('/login', routeFactory:(settings, uniqueId) {
    return PageRouteBuilder<dynamic>(
      settings: settings,
      pageBuilder: (_, __, ___) => LoginPage(),
    );
  });
  @override
  Map<String, FlutterBoostRouteFactory> routeFactory() {
    // TODO: implement register
      return {
        tabbarPage.path:tabbarPage.routeFactory,
        switchParkPage.path:switchParkPage.routeFactory,
        serviceWorkbenchPage.path:serviceWorkbenchPage.routeFactory,
        loginPage.path:loginPage.routeFactory
      };
  }
}

class HZRouter {
  PageModule pageModule = PageModule();
  CommonModule commonModule = CommonModule();

  NativeModule nativeModule = NativeModule();
  Map routerMap = {};

  factory HZRouter() =>_getInstance();
  static HZRouter get instance => _getInstance();
  static HZRouter _instance;
  HZRouter._internal() {
    // 初始化
    routerMap.addAll(pageModule.routeFactory());
    routerMap.addAll(commonModule.routeFactory());
  }
  static HZRouter _getInstance() {
    if (_instance == null) {
      _instance = new HZRouter._internal();
    }
    return _instance;
  }

  Route<dynamic> routeFactory(RouteSettings settings, String uniqueId) {
    FlutterBoostRouteFactory func = routerMap[settings.name];
    if (func == null) {
      return null;
    }
    return func(settings, uniqueId);
  }
}

class RouterModule {
  // ignore: missing_return
  Map<String,FlutterBoostRouteFactory> routeFactory() {}
}

class RouterPage {
  String path;
  FlutterBoostRouteFactory routeFactory;

  RouterPage(this.path, {this.routeFactory});
}
